package com.e2oto.seller.modules.seller.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.e2oto.seller.R;
import com.e2oto.seller.common.base.RecycleViewAdapter;
import com.e2oto.seller.common.base.RecycleViewHolder;
import com.e2oto.seller.common.utils.LogTools;
import com.e2oto.seller.modules.seller.bean.CityBean;
import com.e2oto.seller.modules.seller.bean.ProvinceBean;
import com.e2oto.seller.modules.seller.ui.SelectCityActivity;
import com.e2oto.seller.modules.seller.ui.SelectDistrictActivity;

import java.util.List;

/**
 * Created by ZhangLiQiang on 2017/11/14.
 */

public class SelectCityAdapter extends RecycleViewAdapter<CityBean> {

    private Context mContext;

    public SelectCityAdapter(List<CityBean> dataList, Context context) {
        super(dataList);
        this.mContext = context;

    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_address;
    }

    @Override
    public void convert(RecycleViewHolder holder, CityBean bean, int position) {
        TextView name = (TextView) holder.getView(R.id.item_address_name);
        name.setText(bean.getName());
        ImageView isSelected = (ImageView) holder.getView(R.id.item_address_is_selected);
        name.setText(bean.getName());
        if (bean.isSelected()) {
            isSelected.setVisibility(View.VISIBLE);
        } else {
            isSelected.setVisibility(View.GONE);
        }
    }

    public void resetStatus() {
        for (int i = 0; i < getDataList().size(); i++) {
            if (getDataList().get(i).isSelected()) {
                getDataList().get(i).setSelected(false);
            }
        }
    }
    public CityBean getSelectedCityBean() {
        for (int i = 0; i < getDataList().size(); i++) {
            if (getDataList().get(i).isSelected()) {
                return getDataList().get(i);
            }
        }
        return null;
    }
}
